package www.shuang.investor.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import www.shuang.common.util.PageInfoUtil;
import www.shuang.investor.dao.AInvestorDao;
import www.shuang.investor.pojo.AInvestor;
import www.shuang.investor.service.IAInvestorService;
@Service("investorService")
public class AInvestorServiceImpl implements IAInvestorService
{	@Resource
	protected AInvestorDao investorDao;
	@Override
	public AInvestor findOneAInvestorService(Map<String, Object> condMap)
	{
		return this.investorDao.findOne(condMap);
	}

	@Override
	public List<AInvestor> findCondListAInvestorService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		/*pageCount==true:拿总记录数:
		pageCount == false:分页数据:
		pageCount 为null不分页查询*/
		List<AInvestor> investorList=new ArrayList<AInvestor>();
		//处理关键字
		if(condMap.get("keyword")!= null){
			condMap.put("keyword", "%"+condMap.get("keyword")+"%");
		}
		//分页查询
		if(pageInfoUtil != null){
			condMap.put("pageCount", "true");
			investorList = this.investorDao.findCondList(condMap);
			//放在id属性上
			pageInfoUtil.setTotalRecord(investorList.get(0).getId());
			condMap.put("pageCount", "false");
			condMap.put("currentRecord", pageInfoUtil.getCurrRecord());
			condMap.put("pageSize",pageInfoUtil.getPageSize());
			investorList=this.investorDao.findCondList(condMap);
			
		}else{
			investorList=this.investorDao.findCondList(condMap);
		}
		return investorList;
	}

	@Override
	public JSONObject insertOneAInvestorService(AInvestor investor)
	{
		JSONObject resultJSON=new JSONObject();
		int res=this.investorDao.insert(investor);
	if(res>0){
		resultJSON.put("code", "0");
		resultJSON.put("info", "添加成功");
		//添加二级json
		JSONObject dataJSON=new JSONObject();
		dataJSON.put("affect",res);
		resultJSON.put("data", dataJSON);
	}else{
		resultJSON.put("code", "1");
		resultJSON.put("info", "添加失败");
	}
	
	return resultJSON;
	}

	@Override
	public JSONObject updateOneAInvestorService(AInvestor investor)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public JSONObject deleteOneAInvestorService(AInvestor investor)
	{
		// TODO Auto-generated method stub
		return null;
	}

}
